<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../js/vue.js"></script>
    <style>
        #app {
            width: 80px;
            /* height: 300px; */
            margin: 100px auto;
        }

        .menu {
            background-color: #fff;
        }

        .item {
            /* width: 100px;
            height: 200px; */
            cursor: context-menu;
            background-color: #f1f1f1;
            color: #333;
        }

        .item+.item {
            margin-top: 30px;
        }

        .box {
            margin-left: 20px;
            color: #555;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="menu">
            <div class="item" @click="close">关闭全部</div>
            <div class="item" v-for="item in list" :key="item.id" @click="active(item.id)" >{{item.msg}}
                <div class="box" v-if="index == item.id" v-for="info in item.list" :key="info.id">{{info.msg}}</div>
            </div>

        </div>
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            index: [1],
            list: [
                {
                    id: 1, msg: "菜单一", list: [
                        {id: 11, msg: "菜单1-1"},
                        {id: 12, msg: "菜单1-2"},
                        {id: 13, msg: "菜单1-3"}
                    ]

                },
                {
                    id: 2, msg: "菜单二", list: [
                        {id: 21, msg: "菜单2-1"},
                        {id: 22, msg: "菜单2-2"},
                        {id: 23, msg: "菜单2-3"}
                    ]
                },
                {
                    id: 3, msg: "菜单三", list: [
                        {id: 31, msg: "菜单3-1"},
                        {id: 32, msg: "菜单3-2"},
                        {id: 33, msg: "菜单3-3"}
                    ]
                },
                {
                    id: 4, msg: "菜单四", list: [
                        {id: 41, msg: "菜单4-1"},
                        {id: 42, msg: "菜单4-2"},
                        {id: 43, msg: "菜单4-3"}
                    ]
                }
            ],
        },
        methods: {
            active(id) {
                if(this.index == id) {
                    this.index = "";
                } else {
                    this.index = id;
                }
            },
            close() {
                this.index = "";
            }
        },
        watch: {

        }
    })
</script>

</html>